<h:form id="formOrgao" 
        xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:p="http://primefaces.org/ui"
        xmlns:f="http://java.sun.com/jsf/core">

    <script language="JavaScript" src = "scripts/script.js"/>

    <h:panelGrid columns="3">

        <h:panelGroup>
            <h:outputLabel value="Código"/><br/>
            <p:inputMask value="#{orgaoBean.orgao.codigo}" required="true" 
                         maxlength="2" size="4" mask="99"/>
        </h:panelGroup>

        <h:panelGroup>
            <h:outputLabel value="CNPJ"/><br/>
            <p:inputMask mask="99.999.999/9999-99" size="22" value="#{orgaoBean.orgao.documento.cnpj}" 
                         required="true"/>
        </h:panelGroup>

        <h:panelGroup>
            <h:outputLabel value="Tipo"/><br/>
            <p:selectOneMenu value="#{orgaoBean.orgao.tipoOrgao}" style="width: 270px" 
                             required="true" requiredMessage="Campo Obrigatório">

                <f:selectItem itemLabel="Selecione" />
                <f:selectItems value="#{orgaoBean.tiposOrgao}"/>
                <f:converter converterId="simpleEntityConverter"/>

            </p:selectOneMenu>
        </h:panelGroup>
    </h:panelGrid>

    <h:panelGrid columns="1" style="width: 100%">

        <h:panelGroup>

            <h:outputLabel value="Nome"/><br/>
            <p:inputText styleClass="up" value="#{orgaoBean.orgao.nome}"
                         style="width: 96%" />

        </h:panelGroup>

    </h:panelGrid>

    <p:panel header="Informações para Contato">

        <h:panelGrid columns="3" style="width: 100%">

            <h:panelGroup>
                <h:outputLabel value="Telefone"/><br/>
                <p:inputMask mask="(99)9999-9999" value="#{orgaoBean.orgao.contato.telefone}" size="15"/>
            </h:panelGroup>

            <h:panelGroup>
                <h:outputLabel value="Fax"/><br/>
                <p:inputMask mask="(99)9999-9999" value="#{orgaoBean.orgao.contato.fax}" size="15"/>
            </h:panelGroup>

            <h:panelGroup>
                <h:outputLabel value="Email"/><br/>
                <p:inputText styleClass="up" value="#{orgaoBean.orgao.contato.email}" size="30"/>
            </h:panelGroup>

        </h:panelGrid>

    </p:panel>

    <p:panel header="Endereço">

        <h:panelGrid columns="3" style="width: 100%">

            <h:panelGroup>
                <h:outputLabel value="Rua"/><br/>
                <p:inputText styleClass="up" value="#{orgaoBean.orgao.endereco.logradouro}" 
                             size="40" required="true"/>
            </h:panelGroup>

            <h:panelGroup>
                <h:outputLabel value="Número"/><br/>
                <p:inputText styleClass="up" value="#{orgaoBean.orgao.endereco.numero}" 
                             size="5" required="true"/>
            </h:panelGroup>

            <h:panelGroup>
                <h:outputLabel value="Bairro"/><br/>
                <p:inputText styleClass="up" value="#{orgaoBean.orgao.endereco.bairro}"/>
            </h:panelGroup>

        </h:panelGrid>

        <h:panelGrid columns="3" style="width: 100%">

            <h:panelGroup>
                <h:outputLabel value="CEP"/><br/>
                <p:inputMask mask="99.999-999" value="#{orgaoBean.orgao.endereco.cep}" size="15"/>
            </h:panelGroup>

            <h:panelGroup>

                <h:outputLabel value="Estado"/><br/>
                <p:selectOneMenu value="#{orgaoBean.orgao.endereco.municipio.estado}" 
                                 style="width: 130px" required="true"
                                 filter="true" filterMatchMode="startsWith">

                    <f:selectItem itemLabel="Selecione"/>
                    <f:selectItems value="#{orgaoBean.estados}" />
                    <f:converter converterId="simpleEntityConverter"/>
                    <p:ajax event="change" update="cbxMunicipios"/>

                </p:selectOneMenu>

            </h:panelGroup>

            <h:panelGroup>

                <h:outputLabel value="Município"/><br/>
                <p:selectOneMenu id="cbxMunicipios" 
                                 value="#{orgaoBean.orgao.endereco.municipio}" 
                                 style="width: 200px" 
                                 required="true" requiredMessage="Campo de preenchimento obrigatório"
                                 filter="true" filterMatchMode="startsWith">

                    <f:selectItem itemLabel="Selecione"/>
                    <f:selectItems value="#{orgaoBean.municipios}"/>
                    <f:converter converterId="simpleEntityConverter"/>

                </p:selectOneMenu>

            </h:panelGroup>

        </h:panelGrid>
        
    </p:panel>

    <hr/>

    <p:commandButton id="btnGravar" value="Gravar" 
                     actionListener="#{orgaoBean.adicionarEditarFim}"
                     update="formOrgao" />

    <p:commandButton value="Cancelar" 
                     actionListener="#{orgaoBean.cancelar}"
                     immediate="true"/>

</h:form>


